<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul {
      list-style: none;
      width: 300px;
      border: 1px dashed #f40;
    }

    li {
      line-height: 30px;
      padding-left: 20px;
    }
  </style>
</head>

<body>
  <ul id="list">
    <li>慕寒1</li>
    <li>慕寒2</li>
    <li>慕寒3</li>
    <li>慕寒4</li>
    <li>慕寒5</li>
    <li>慕寒6</li>
    <li>慕寒7</li>
    <li>慕寒8</li>
  </ul>

  <script src="js/common.js"></script>
  <script>
    var list = my$("list");
    var items = list.children;
    /*
      事件委托：将子元素触发的事件委托给父元素去触发，借用事件函数中的事件对象 e
      只有触发事件，函数内部就会得到一个事件对象，里面存储了关于的事件的各种数据
      e.target 记录真正触发事件的事件源
    */
    addEvent(list, "click", function (e) {
      e = e || window.event;
      //console.log(e.target);
      for (var i = 0; i < items.length; i++) {
        items[i].style.backgroundColor = "";
      }
      e.target.style.backgroundColor = "pink";
    })
  </script>
</body>

</html>